package com.douwong.student.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * @autor yichao
 * @time 2017/3/279:16
 * @des  程序运行信息
 */
public class AppInfoUtils {

    public static  PackageInfo getPackageInfo(Context context){
        PackageInfo info = null;
        try {
            info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace(System.err);
        }
        if(info == null) info = new PackageInfo();
        return info;
    }


    public  static String getVersionName(Context context){
        PackageInfo packageInfo = getPackageInfo(context);
       return packageInfo.versionName;


    }
    public static int getVersionCode(Context context){
        PackageInfo packageInfo = getPackageInfo(context);
        return  packageInfo.versionCode;
    }

}
